<template>
    <el-form :model="form_active2" label-width="120px">
        <el-form-item label="赠送积分：">
            <el-input v-model="form_active2.giftPoint" />
        </el-form-item>
        <el-form-item label="赠送成长值：">
            <el-input v-model="form_active2.giftGrowth" />
        </el-form-item>
        <el-form-item label="积分购买限制：">
            <el-input v-model="form_active2.usePointLimit" />
        </el-form-item>
        <el-form-item label="预告商品：">
            <el-switch v-model="form_active2.previewStatus" :active-value="1" :inactive-value="0" />
        </el-form-item>
        <el-form-item label="商品上架：">
            <el-switch v-model="form_active2.publishStatus" :active-value="1" :inactive-value="0" />
        </el-form-item>
        <el-form-item label="商品推荐：">
            <el-form-item label="新品" label-width="50px">
                <template #default>
                    <el-switch v-model="form_active2.newStatus" :active-value="1" :inactive-value="0" />
                </template>
            </el-form-item>
            <el-form-item label="推荐" label-width="50px">
                <template #default>
                    <el-switch v-model="form_active2.recommandStatus" :active-value="1" :inactive-value="0" />
                </template>
            </el-form-item>
        </el-form-item>
        <el-form-item label="服务保证：">
            <el-checkbox-group>
                <el-checkbox label="1" name="1">无忧退货</el-checkbox>
                <el-checkbox label="2" name="2">快速退货</el-checkbox>
                <el-checkbox label="3" name="3">免费包邮</el-checkbox>
            </el-checkbox-group>
        </el-form-item>
        <el-form-item label="详细页标题：">
            <el-input v-model="form_active2.detailTitle" />
        </el-form-item>
        <el-form-item label="详细页描述：">
            <el-input v-model="form_active2.detailDesc" />
        </el-form-item>
        <el-form-item label="商品关键字：">
            <el-input v-model="form_active2.keywords" />
        </el-form-item>
        <el-form-item label="商品备注：">
            <el-input v-model="form_active2.note" type="textarea" />
        </el-form-item>
        <el-form-item label="选择优惠方式：">
            <el-radio-group v-model="form_active2.promotionType">
                <el-radio-button label="0">无优惠</el-radio-button>
                <el-radio-button label="1">特惠促销</el-radio-button>
                <el-radio-button label="2">会员价格</el-radio-button>
                <el-radio-button label="3">阶梯价格</el-radio-button>
                <el-radio-button label="4">满减价格</el-radio-button>
            </el-radio-group>
        </el-form-item>
        <el-form-item>
            <keep-alive>
                <SpecialPromotions @getPrice="getPrice" @getEndTime="getEndTime" @getStartTime="getStartTime"
                    v-if="form_active2.promotionType === '1'" />
            </keep-alive>
            <keep-alive>
                <VipPrice @getPlatinum="getPlatinum" @getGold="getGold" @getDiamond="getDiamond"
                    v-if="form_active2.promotionType === '2'" />
            </keep-alive>
            <LadderPrice @getCount="getCount" v-if="form_active2.promotionType === '3'" />
            <keep-alive>
                <FullMinusPrice @getFullPrice="getFullPrice" v-if="form_active2.promotionType === '4'" />
            </keep-alive>
        </el-form-item>
        <el-form-item>
            <el-button style="margin-top: 12px" @click="previous">上一步，填写商品信息</el-button>
            <el-button style="margin-top: 12px" @click="next" type="primary">下一步，填写商品促销</el-button>
        </el-form-item>
    </el-form>
</template>

<script setup lang="ts">
import SpecialPromotions from "./PreferentialMethods/SpecialPromotions.vue";
import VipPrice from "./PreferentialMethods/VipPrice.vue";
import LadderPrice from "./PreferentialMethods/LadderPrice.vue";
import FullMinusPrice from "./PreferentialMethods/FullMinusPrice.vue";
import { ref } from 'vue'
import { useToPro } from "@/store/AddToPro"

const useAddToPro = useToPro()

const emits = defineEmits<{
    (e: "next"): void
    (e: "previous"): void
}>()

const previous = () => {
    emits("previous")
}

const form_active2 = ref({
    giftPoint: 0, // 赠送积分1
    giftGrowth: 0, // 赠送成长值1
    usePointLimit: 0, // 购买限制 1
    previewStatus: 0, // 0->不是新品；1->新品 1
    publishStatus: 0, // 0->下架；1->上架 1
    newStatus: 0, // 0->不是新品；1->新品 1
    recommandStatus: 0, // 0->不推荐；1->推荐 1
    serviceIds: "1,2,3", // 1->无忧退货；2->快速退款；3->免费包邮 1
    detailTitle: "", // 详情页标题1
    detailDesc: "", // 详情描述1
    keywords: "", // 关键字1
    note: "", // 备注 1
    promotionType: "0",// 促销方式 1
    // 下面是特惠促销子组件
    promotionStartTime: "", // 开始时间 1
    promotionEndTime: "", // 结束时间 1
    promotionPrice: "", // 促销价格 1
    // 会员价格
    memberPriceList: [] as any, // 1
    // 阶梯价格
    productLadderList: [] as any, //1 
    // 满/立减
    productFullReductionList: [] as any //1
})

const getStartTime = (val: string) => {
    form_active2.value.promotionStartTime = val
}

const getEndTime = (val: string) => {
    form_active2.value.promotionEndTime = val
}

const getPrice = (val: string) => {
    form_active2.value.promotionPrice = val
}

const getGold = (val: vipprice) => { // 获取黄金的对象
    form_active2.value.memberPriceList.push(val)
}

const getDiamond = (val: vipprice) => { // 获取钻石的对象
    form_active2.value.memberPriceList.push(val)
}

const getPlatinum = (val: vipprice) => { // 获取白金的对象
    form_active2.value.memberPriceList.push(val)
}

const getCount = (val: IDiscount) => { // 折扣操作
    form_active2.value.productLadderList.push(val)
}

const getFullPrice = (val: IfullPrice) => { // 满/立减
    form_active2.value.productLadderList.push(val)
}

const next = () => {
    console.log(form_active2);
    useAddToPro.PushData(form_active2.value)
    emits("next")
}
</script>

<style scoped></style>